﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NS.Utilities;
using Filter;
using Newtonsoft.Json.Linq;
using HttpUtility;
using WechatModel;

namespace WechatDAL
{
    public class W_DepartmentDal
    {
        /// <summary>
        /// 创建部门
        /// </summary>
        /// <param name="m">部门实体对象</param>
        /// <returns></returns>
        public bool Insert(W_DepartmentInfo m)
        {
            JObject jo = Poster.Post(WechatAPI4Ent.AddDepartment, JsonHelper.T2JSON(m));
            if (jo == null)
                return false;
            else
            {
                if (jo["errcode"].ToString() == "0" && jo["errmsg"].ToString() == "created")
                    return true;
                else
                    return false;
            }
        }

        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public bool Update(W_DepartmentInfo m)
        {
            JObject jo = Poster.Post(WechatAPI4Ent.UpdateDepartment, JsonHelper.T2JSON(m));
            if (jo == null)
                return false;
            else
            {
                if (jo["errcode"].ToString() == "0" && jo["errmsg"].ToString() == "updated")
                    return true;
                else
                    return false;
            }
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            JObject jo = Poster.Get(WechatAPI4Ent.DeleteDepartment, id.ToString());
            if (jo == null)
                return false;
            else
            {
                if (jo["errcode"].ToString() == "0" && jo["errmsg"].ToString() == "deleted")
                    return true;
                else
                    return false;
            }
        }
    }
}
